package com.juc.cyclicbarrier.cyclicbarrier2;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class MyThread extends Thread {
    /**
     * 线程个数大于parties 数量
     */
	
	private CyclicBarrier cbRef;
	
	public MyThread(CyclicBarrier cbRef) {
		super();
		this.cbRef = cbRef;
	}
	
	@Override
	public void run() {
		try {
			  System.out.println(Thread.currentThread().getName() + " begin =" + System.currentTimeMillis() + " 等待凑齐2个继续运行");
			  cbRef.await();
			  System.out.println(Thread.currentThread().getName() + " end =" + System.currentTimeMillis() + " 已经凑齐2个继续运行");
 
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BrokenBarrierException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
